import { Component } from 'react';

import {  Button, Group, Toast,Dialog,CheckboxField,Boxs,TextareaField,Slot } from 'saltui';
const { HBox,Box } = Boxs;
import DB from 'db';

import SelectMember from 'components/selectMember';
import './PageHome.less';

const {
	IconButton,
	ButtonGroup,
} = Button;
let iconIndex = 2;
export default class PageHome extends Component {
	constructor(props) {
		super(props);

		//关闭加载页的遮罩效果
		$(".loading-containter").hide();


		//let processInstanceId = this.props.params.processInstanceId;
		//let handleUserId = this.props.params.assignee;
		
		let operate = this.props.params.operate;//操作类型(1:通过)
		let taskIds = this.props.params.taskIds;//任务ids
		let processInstanceIds = this.props.params.processInstanceIds;//多个流程实例id
		let code = this.props.params.code;//流程code
		let hasCommentField = this.props.params.hasCommentField;//是否有批示意见
		let urgent = this.props.params.urgent;//是否紧急
		let isStart = this.props.params.isStart;//是否是流程起始节点
		
		let category = this.props.params.category;//模块
        let module = this.props.params.module;//分类
        if(!module){
            module = "document";
        }
		let urgentList=[
            {
            value:"1",
            checked:urgent=="1"?true:false,
            content:'紧急',
            disable:false
            }
		];
		//是否保存为常用语
        let savePhraseList=[
            {
            value:"1",
            checked:false,
            content:'是否保存为常用语',
            disable:false
            }
        ];
		this.state = {
			module:module,//模块
			category:category, //分类
			taskIds: taskIds,
			operate:operate,
			processInstanceIds: processInstanceIds, //数据id
			spyj:'',//审批意见
			hasCommentField:hasCommentField,//是否有审批意见
			urgent:urgent,//紧急状态，0：不紧急
			code:code,//流程code
			urgentSelectList:[],//已选择的紧急选项
            urgentList:urgentList,//紧急选项
			urgentHidden:true,//紧急是否显示
			nextActivityList:[],//下一个后继活动节点列表
			nextRadomList:[],//下一个随机活动节点列表
			isStart:isStart=="1"?true:false,//是否是起点
			directlySubmit:'',//是否直接提交
			phraseList:[],//常用语列表
            choosePhrase:[],//常用语列表选择
            savePhraseList:savePhraseList,//是否保存为常用语的选项列表
            savePhrase:[],//是否保存为常用语，1是，0否
		};

		FlowCommon = require('pages/flow_common/'+module);//引入扩展js


		let t = this;
		let userId = document.getElementById("userHiddenId").value;
		dd.util.domainStorage.getItem({ //点击帮助页面
		name:'document_helpNew_'+userId , // 存储信息的key值
		onSuccess : function(info) {
			let helpNew = info.value;
			if( typeof(helpNew) != 'undefined' && helpNew != '' ){
			iconIndex = 1;
			}
			t.initButton();
		},
		onFail : function(err) {
		}
		});
	}
	//初始化按钮
	initButton(){
	    //设置帮助
	     /*dd.biz.navigation.setIcon({
	        showIcon : true,//是否显示icon
	        iconIndex : iconIndex,//显示的iconIndex,如上图
	        onSuccess : function(result) {
	            location.hash='document/help_index';
	        },
	        onFail : function(err) {
	        }
		});*/
	    //  dd.biz.navigation.setTitle({
	    //       title : title,//控制标题文本，空字符串表示显示默认文本
	    //       onSuccess : function(result) {
	    //       },
	    //       onFail : function(err) {}
	    //     });
	     dd.biz.navigation.setRight({
	        show: false,//控制按钮显示， true 显示， false 隐藏， 默认true
	        onSuccess : function(result) {
	        },
	        onFail : function(err) {}
	    });
	}
	componentDidMount() {
		let t = this;
		var operate = t.state.operate;
		if(operate == 1){//通过
			this.getNextActivity();
		} 
	}

	//获取下一个办理的节点
	getNextActivity(){
		let t = this;
		let taskIds = t.state.taskIds;
		let processInstanceIds = t.state.processInstanceIds;
		let taskId = '';
		let processInstanceId = '';
		if(taskIds){
			let taskArray = taskIds.split(",");
			let processInstanceIdArray = processInstanceIds.split(",");
			taskId = taskArray[0];
			processInstanceId = processInstanceIdArray[0];
		}
		
		//是否有批示意见
		let hasCommentField = t.state.hasCommentField;
		if(!hasCommentField){
			hasCommentField='0';
		}

		//紧急
		let urgent = t.state.urgent;
		if(!urgent){
			urgent = '0';
		}

		//是否有锁
		//let lock = t.state.lock;

		//流程编码
		let code = t.state.code;

		//是否是起点
		let isStart = t.state.isStart;
		let nextActivityList = [];
		var nextRadomList = [];
		DB.FlowModuleAPI.getNextActivity(
			{
				taskId:taskId,
				code:code
			}
		).then((content) => {
			let nextList= content.activityList;//下一个后继节点列表
			let radomList = content.radomList;//下一个随机活动节点
			let maxOutgoing=content.maxOutgoing;
			var isRadio = maxOutgoing == 1;//单选还是多选

			var param = {
				taskIds: t.state.taskIds,
				processInstanceIds:t.state.processInstanceIds,
				module:"document",
				//lock:lock,
				dealActionName:"通过"
			} 
			if(nextList==null || nextList=='' || nextList.length==0){
				if(hasCommentField=="1"){
						
					t.setState({
						urgentHidden:true,
						urgentList:[],
						//lock:lock,
						hasCommentField:hasCommentField,
						isStart:isStart,
						directlySubmit:'0'
					});
				}else{
					t.setState({
						urgentHidden:true,
						urgentList:[],
						directlySubmit:'1'
					});
					t.sendFlowClick(param);
				}
			}else if(nextList.length==1 && nextList[0]['end']){
				if(hasCommentField=="1"){
					t.setState({
						urgentHidden:true,
						urgentList:[],
						//lock:lock,
						hasCommentField:hasCommentField,
						isStart:isStart,
						directlySubmit:'0'
					});
				}else{
					t.setState({
						urgentHidden:true,
						urgentList:[],
						directlySubmit:'1'
					});
					t.sendFlowClick(param);
				}
			}else{
					
				//let tasktype = t.state.tasktype;
				let urgentHidden = false;
				// var path = '#/approval/approve-choosenode/';
				let checkActi = "0";
				//随机节点
				if(typeof(radomList)!= 'undefined' && radomList != null){
					radomList.map(function(item){
						var checkedItem = {};
						var selectUserReadOnly = false;
						var personValue = [];//选中的人
						var participantMode = item.isCross == 2?'1':'0';//判断选人是单选还是多选,0,1单选，2包含随机多选
						var commonUsedData = [];//自定义选人的范围,常用
						var popCode = "";
						var chooseType = "";
						if(item.type == 3 ){ //指定人选择
							selectUserReadOnly = true;
							popCode = 'org';//选人组件code
							chooseType = "userNotOrg"; 
							var participantList = item.participantList;
							if(participantList != null && participantList != "" && participantList.length>0){
								for(var i=0; i<participantList.length; i++ ){
									if(participantList[i].type != "user"){
										var children = participantList[i].children;
										for(var j=0; j<children.length; j++ ){
											var personValueItem = {scopeType:"user",scopeValue:children[j].id,scopeName:children[j].name,imageId:""};
											personValue.push(personValueItem);
										}
									}else{
										var personValueItem = {scopeType:"user",scopeValue:participantList[i].id,scopeName:participantList[i].name,imageId:""};
										personValue.push(personValueItem);
									}
									
								}
							}
							
						}else if(item.type == 1){//选择所有人
							selectUserReadOnly = false;
							chooseType = "userNotOrg"; 
							var commonUsedId = '';//常用选择的用户id
							var participantList = item.participantList;
							if(participantList != null && participantList != "" && participantList.length>0){
								for(var i=0; i<participantList.length; i++ ){
									if(participantList[i].type != "user"){
										var children = participantList[i].children;
										for(var j=0; j<children.length; j++ ){
											var personValueItem = {scopeType:"user",scopeValue:children[j].id,scopeName:children[j].name,imageId:""};
											if(commonUsedId.indexOf(children[j].id) == -1){
												commonUsedId += children[j].id+',';
												commonUsedData.push(personValueItem);
											}
										}
									}else{
										var personValueItem = {scopeType:"user",scopeValue:participantList[i].id,scopeName:participantList[i].name,imageId:""};
										if(commonUsedId.indexOf(participantList[i].id) == -1){
											commonUsedId += participantList[i].id+',';
											commonUsedData.push(personValueItem);
										}
									}
									
								}
								if(commonUsedData.length>0){
									popCode = "common,org";
								}else{
									popCode = "org";
								}
							}else{
								popCode = "org";
							}
						}else{//指定候选人
							selectUserReadOnly = false;
							var popCode = 'common';//选人组件code
							var commonUsedId = '';//常用选择的用户id
							var participantList = item.participantList;
							if(participantList != null && participantList != "" && participantList.length>0){
								for(var i=0; i<participantList.length; i++ ){
									if(participantList[i].type != "user"){
										var children = participantList[i].children;
										for(var j=0; j<children.length; j++ ){
											var personValueItem = {scopeType:"user",scopeValue:children[j].id,scopeName:children[j].name,imageId:""};
											if(commonUsedId.indexOf(children[j].id) == -1){
												commonUsedId += children[j].id+',';
												commonUsedData.push(personValueItem);
											}
										}
									}else{
										var personValueItem = {scopeType:"user",scopeValue:participantList[i].id,scopeName:participantList[i].name,imageId:""};
										if(commonUsedId.indexOf(participantList[i].id) == -1){
											commonUsedId += participantList[i].id+',';
											commonUsedData.push(personValueItem);
										}
									}
									
								}
							}
						}
						checkedItem.code = popCode;
						checkedItem.chooseType = chooseType;
						checkedItem.commonUsedData = commonUsedData;
						checkedItem.participantMode = participantMode;//选人单选还是多选，1多选，0单选
						checkedItem.personValue = personValue;
						checkedItem.selectUserReadOnly = selectUserReadOnly;
						checkedItem.value = item.id;
						checkedItem.name = item.name;
						checkedItem.arrow = true;
						checkedItem.show = true;
						checkedItem.type = item.type;
						checkedItem.end = item.end;
						checkedItem.level = item.level;
						if(item.must==true ){//必须
							checkedItem.disable = true;
							checkedItem.checked = true;
							checkActi = "1";
						}else if(item.defaultFlow==true ){//默认节点
							checkedItem.disable = false;
							checkedItem.checked = true;
							checkActi = "1";
						}else{
							checkedItem.disable = false;
							checkedItem.checked = false;
						}
						if(checkedItem.checked == true && checkedItem.end==true){ //当结束节点且选中时
							// t.setState({
							//   urgentHidden:true,
							//   urgentList:[]
							// });
							urgentHidden = true;
						}
						checkedItem.isRadio = isRadio;//判断是否是单选还是多选
						nextRadomList.push(checkedItem);
					});
				}
				nextList.map(function(item){
					if(item.nodeType=='radom'){//随机
						return false;
					}
					var checkedItem = {};
					var selectUserReadOnly = false;
					var personValue = [];//选中的人
					var participantMode = item.participantMode;//判断选人是单选还是多选
					var commonUsedData = [];//自定义选人的范围,常用
					var popCode = "";
					var chooseType = "";
					if(item.type == 3 ){ //指定人选择
						selectUserReadOnly = true;
						popCode = 'org';//选人组件code
						chooseType = "userNotOrg"; 
						var participantList = item.participantList;
						if(participantList != null && participantList != "" && participantList.length>0){
							for(var i=0; i<participantList.length; i++ ){
								if(participantList[i].type != "user"){
									var children = participantList[i].children;
									for(var j=0; j<children.length; j++ ){
										var personValueItem = {scopeType:"user",scopeValue:children[j].id,scopeName:children[j].name,imageId:""};
										personValue.push(personValueItem);
									}
								}else{
									var personValueItem = {scopeType:"user",scopeValue:participantList[i].id,scopeName:participantList[i].name,imageId:""};
									personValue.push(personValueItem);
								}
								
							}
						}
						
					}else if(item.type == 1){//选择所有人
						selectUserReadOnly = false;
						chooseType = "userNotOrg"; 
						var commonUsedId = '';//常用选择范围
						var participantList = item.participantList;
						if(participantList != null && participantList != "" && participantList.length>0){
							for(var i=0; i<participantList.length; i++ ){
								if(participantList[i].type != "user"){
									var children = participantList[i].children;
									for(var j=0; j<children.length; j++ ){
										var personValueItem = {scopeType:"user",scopeValue:children[j].id,scopeName:children[j].name,imageId:""};
										if(commonUsedId.indexOf(children[j].id) == -1){
											commonUsedId += children[j].id+',';
											commonUsedData.push(personValueItem);
										}
									}
								}else{
									var personValueItem = {scopeType:"user",scopeValue:participantList[i].id,scopeName:participantList[i].name,imageId:""};
									if(commonUsedId.indexOf(participantList[i].id) == -1){
										commonUsedId += participantList[i].id+',';
										commonUsedData.push(personValueItem);
									}
								}
								
							}
							if(commonUsedData.length>0){
								popCode = "common,org";
							}else{
								popCode = "org";
							}
						}else{
							popCode = "org";
						}
					}else{//指定候选人
						selectUserReadOnly = false;
						var popCode = 'common';//选人组件code
						var participantList = item.participantList;
						if(participantList != null && participantList != "" && participantList.length>0){
							for(var i=0; i<participantList.length; i++ ){
								if(participantList[i].type != "user"){
									var children = participantList[i].children;
									for(var j=0; j<children.length; j++ ){
										var personValueItem = {scopeType:"user",scopeValue:children[j].id,scopeName:children[j].name,imageId:""};
										personValue.push(personValueItem);
									}
								}else{
									var personValueItem = {scopeType:"user",scopeValue:participantList[i].id,scopeName:participantList[i].name,imageId:""};
									personValue.push(personValueItem);
								}
								
							}
						}
					}
					checkedItem.code = popCode;
					checkedItem.chooseType = chooseType;
					checkedItem.commonUsedData = commonUsedData;
					checkedItem.participantMode = participantMode;//选人单选还是多选，1多选，0单选
					checkedItem.personValue = personValue;
					checkedItem.selectUserReadOnly = selectUserReadOnly;
					checkedItem.value = item.id;
					checkedItem.name = item.name;
					checkedItem.arrow = true;
					checkedItem.show = true;
					checkedItem.type = item.type;
					checkedItem.end = item.end;
					checkedItem.level = item.level;
					if(item.must==true ){//必须
						checkedItem.disable = true;
						checkedItem.checked = true;
						checkActi = "1";
					}else if(item.defaultFlow==true ){//默认节点
						checkedItem.disable = false;
						checkedItem.checked = true;
						checkActi = "1";
					}else{
						checkedItem.disable = false;
						checkedItem.checked = false;
					}
					if(checkedItem.checked == true && checkedItem.end==true){ //当结束节点且选中时
						// t.setState({
						//   urgentHidden:true,
						//   urgentList:[]
						// });
						urgentHidden = true;
					}
					checkedItem.isRadio = isRadio;//判断是否是单选还是多选
					nextActivityList.push(checkedItem);
				});
				if(checkActi == "0" && isRadio == true){//如果没有默认选中的下一个节点且是单选，则第一个默认选中
					if(nextActivityList.length>0 && nextRadomList.length == 0){
						nextActivityList[0].checked = true;
					}else if(nextRadomList.length>0 && nextActivityList.length == 0){
						nextRadomList[0].checked = true;
					}
				}

				//紧急
				let urgent = t.state.urgent;
				let urgentList = t.state.urgentList;
				let urgentSelectList = [];
				if(urgentHidden == false){ //当紧急状态显示时把判断是否选中值
					if(urgent == '1'){
						urgentList[0].checked = true;
						urgentSelectList = urgentList;
					}
				}
				t.setState({
					nextRadomList:nextRadomList,
					nextActivityList:nextActivityList,
					urgentSelectList:urgentSelectList,
					urgentList:urgentList,
					urgentHidden:urgentHidden,
					//lock:lock,
					hasCommentField:hasCommentField,
					isStart:isStart,
					directlySubmit:'0'
				},function(){
					for(var i=0;i<nextActivityList.length; i++){
						if(nextActivityList[i].personValue.length>0 || nextActivityList[i].commonUsedData.length>0){
							t.refs[nextActivityList[i].value+"_"+i].initSelectData();
						}
					}
					for(var i=0;i<nextRadomList.length; i++){
						if(nextRadomList[i].personValue.length>0 || nextRadomList[i].commonUsedData.length>0){
							t.refs[nextRadomList[i].value+"_"+i].initSelectData();
						}
					}
				});
			}
		
		}).catch((error) => {
			if(typeof(error.errorMsg) == 'undefined'){
				Toast.show({
					type: 'error',
					content: '请求出错'
				});
			}else{
				Toast.show({
					type: 'error',
					content: error.errorMsg
				});
			}
		});
		
		
	}


	//提交点击
	handleSubmitClick() {
		let t = this;
		let comment = t.state.spyj;
        if(comment != ''){
            if(comment.length>200){
                Toast.show({
                    type: 'error',
                    content: '意见不能多于200字！',
                });
                return false;
            }
		}
		
		//判断是否保存常用语
        let savePhrase = this.state.savePhrase;
        if(savePhrase.length>0 && comment != ''){
            DB.FlowModuleAPI.savePersonalPhrase({
                content:comment
            }).then((content) => {
            }).catch((error) => {
                console.error(error);
            });
		}
		
		var operate = this.state.operate;
		if(operate == 1){ //提交审批
			var nextRadomListSelect = this.state.nextRadomList;
            var nextActivityListSelect = this.state.nextActivityList;
            var nextSelectType = this.state.nextSelectType;//选择随机还是普通
            var selectedActivity = '';
            if(nextRadomListSelect.length>0 || nextActivityListSelect.length>0){ //下一个节点不为空时
            
                selectedActivity = '';
                var nextActivityList = [];
                if(nextSelectType == 'radom'){
                    nextActivityList = nextRadomListSelect;
                }else{
                    nextActivityList = nextActivityListSelect;
                }

                for(let i=0;i<nextActivityList.length;i++){
                    var auditorUserIds = '';
                    var auditorUserNames = '';
                    var checked = nextActivityList[i].checked;
                    if(checked){
                        var personValue = nextActivityList[i].personValue;
                        var isEnd=nextActivityList[i].end;
                        
                        if(personValue.length<=0 && !isEnd){
                            Toast.show({
                                type: 'error',
                                content: '请选择审批人'
                            });
                            return false;
                        }
                        var participantMode = nextActivityList[i].participantMode;
                        if(participantMode == 0){
                            if(personValue.length>1){
                                Toast.show({
                                    type: 'error',
                                    content: nextActivityList[i].name+'节点的参与人只能是单人，请重新设置流程！'
                                });
                                return false;
                            }
                        }
                        if(!isEnd){
                           personValue.map((item, index) => {
                            auditorUserIds += (item.emplId + ',');
                            auditorUserNames +=(item.name+',');
                            });
                            if(auditorUserIds != ''){
                                auditorUserIds = auditorUserIds.substring(0,auditorUserIds.length-1);
                                auditorUserNames = auditorUserNames.substring(0,auditorUserNames.length-1);
                            }
                            selectedActivity += '{"id":"'+nextActivityList[i].value+'","name":"'+nextActivityList[i].name+'","participants":"'+auditorUserIds+'","participantNames":"'+auditorUserNames+'","level":"'+nextActivityList[i].level+'"},'; 
                        }else{
                            selectedActivity += '{"id":"'+nextActivityList[i].value+'","name":"'+nextActivityList[i].name+'","level":"'+nextActivityList[i].level+'"},'; 

                        }
                    }
                }
                if(selectedActivity != ''){
                    selectedActivity = selectedActivity.substring(0,selectedActivity.length-1);
                    selectedActivity = '['+selectedActivity+']';
                }else{
                    Toast.show({
                        type: 'error',
                        content: '请选择节点'
                    });
                    return false;
                }
            }
            let urgentListSelect = t.state.urgentSelectList;
            let urgent = '';
            for(let i=0;i<urgentListSelect.length;i++){
                urgent += urgentListSelect[i].value+",";
            }
            if(urgent != ''){
                urgent = urgent.substring(0,urgent.length-1);
            }
            if(urgent == '' && t.state.urgentHidden==false){
                urgent='0';
            }
           
            var param = {
				taskIds: t.state.taskIds,
				processInstanceIds:t.state.processInstanceIds,
                selectedActivity: selectedActivity,
                module:"document",
                comment:t.state.spyj,
                hasCommentField:t.state.hasCommentField,
                urgency:urgent,
                lock:t.state.lock
            }
            var dealActionName = "";
            if(this.state.isStart == true){
                dealActionName = "提交";
            }else{
                dealActionName = "通过";
            }
            param.dealActionName = dealActionName;
			this.sendFlowClick(param);
		}else if(operate == 2){//驳回
			this.backClick();
		}else if(operate == 3){//转交
			this.transferClick();
		}
		
	}

	//取消
	handleCancelClick(){
		backPage();
	}

	//批量提交发送
	sendFlowClick(param){
		let t = this;
        var editType = '';
        // if(this.props.params.dataId == ''){
        //     editType = "add";
        // }else{
        //     editType = 'edit';
        // }
        param.editType = "edit";

        //var tasktype = this.state.tasktype;
        var content = '是否要通过审批？';
        if(param.dealActionName=='完成'){//随机流程
            content = '是否要完成审批？';
        }
        let db = DB;
        Dialog.confirm({
			locale: 'zh_CN',
			title: '提示',
            content: content,
            onConfirm() {
                db.FlowModuleAPI.completeTaskBatch(param).then((content) => {
                    Toast.show({
                        type: 'success',
                        content: content.successCount+'条成功,'+content.skipCount+'条失败'
					});
					//处理特有参数
					if(typeof FlowCommon.operateCallBack === "function"){
						let returnData = content.successList;
						if(typeof(returnData) != 'undefined' && returnData != null){
							var dataIds = '';
							var status = '';// 1 运行 2 结束
							returnData.map(function(item){
								dataIds += item.dataId+',';
								status = item.status;
							});
							if(dataIds){
								dataIds = dataIds.substring(0,dataIds.length-1);
							}
							let type = 6;
							if(status == 1){
							}else if(status == 2){
								type = 1;
							}
							FlowCommon.operateCallBack({type:type,dataId:dataIds,isBatch:1},t.state);
						}
						
					} 
					
                    setTimeout(
                        function () {
                            backPage();
                        }, 1500);
                }).catch((error) => {
                    if(typeof(error.errorMsg) == 'undefined'){
                        Toast.show({
                            type: 'error',
                            content: '提交出错'
                        });
                    }else{
                        var message = error.errorMsg;
                        if(message.indexOf('exclusive gateway')!=-1){
                            message="请检查判断条件字段是否正确填写！";
                        }
                        Toast.show({
                            type: 'error',
                            content: message
                        });
                    }
                });
            },
        onCancel() {
			if(t.state.directlySubmit == '1'){
				backPage();
			}
        },
    });
	}

	 //选择紧急状态
	 selectUrgent(data){
        this.setState({
            urgentSelectList:data
        });
    }

	 //选择提交审批用户
	 getPersion(i,newValue){
        var nextActivityList = this.state.nextActivityList;
        // for(var i=0; i<newValue.length; i++){
        //     form.personValue.push(newValue[i]);
        // }
        nextActivityList[i].personValue = newValue;
        this.setState({
            nextActivityList
        });
	}
	
	 //选择用户时
	 getChoosePerson(i,personValue,allPerson){
        var nextActivityList = this.state.nextActivityList;
        nextActivityList[i].personValue = personValue;
        nextActivityList[i].allPerson = allPerson;
        this.setState({
            nextActivityList
        });
    }
	
	 //选择节点
	 handleChecked(i,item,e){
        var checked = item.checked;
        var disable = item.disable;
        var isRadio = item.isRadio;
        if(!disable){//只有可选时才改变状态
            let nextActivityList = this.state.nextActivityList;
            if(isRadio){//单选
                if(!checked){
                    for (var j=0; j<nextActivityList.length; j++) {
                        if(nextActivityList[j].disable == true){
                            return false;
                        }
                        nextActivityList[j].checked=false;
                    }
                    nextActivityList[i].checked = !checked;
                    if(checked==false){//当选中时
                        this.refs[item.value+"_"+i].clickAdd();
                    }
                }
            }else{
                nextActivityList[i].checked = !checked;
                if(checked==false){//当选中时
                    this.refs[item.value+"_"+i].clickAdd();
                }
            }
            this.setState({
                nextActivityList:nextActivityList,
            })
        }
     }

     //切换节点内容显示
     handleShow(i,arrow,show,e){
        const t = this;
        var nextActivityList = this.state.nextActivityList;
        nextActivityList[i].arrow = !arrow;
        nextActivityList[i].show = !show;
         t.setState({
            nextActivityList:nextActivityList,
       });
      
	 }
	 
	 
    //修改审批意见
    changeSpyj(newValue) {
        this.setState({
            spyj: newValue,
        });
    }


	//选择常用语
    selectCommonwords(){
		let t = this;
        let phraseListNow = t.state.phraseList;
        if(phraseListNow.length>0){
            t.refs.slotCommonwords.show();
        }else{
            //获取常用语列表
            DB.FlowModuleAPI.getPersonalPhrase({
            }).then((content) => {
                var phraseList1 = []
                content.map(function(item){
                    phraseList1.push({text:item.content,value:item.content});
                });
                var phraseList2 = [];
                phraseList2.push(phraseList1);
                t.setState({
                    phraseList:phraseList2,
                },function(){
                    t.refs.slotCommonwords.show();
                })
            }).catch((error) => {
                Toast.show({
                    type: 'error',
                    content: '网络异常'
                });
            });
        }
	}
	
	 //选择是否保存常用语
	 selectSavePhrase(data){
        this.setState({
            savePhrase:data
        });
    }

    //切换修改常用语
    handleChangeCommonwords(value) {
        // 改变了选中项
        this.setState({
          choosePhrase:value,
        });
      }

    //确认选择语
    handleConfirmCommonwords(commonwords){
        let spyj = this.state.spyj;
        this.setState({
            spyj:spyj+commonwords[0].text
        });
    }


	render() {
		const t = this;
		return (
			<div className="document-details t-PB68" >
					<Group.List className={this.state.hasCommentField == '1' && (this.state.operate == 1 || this.state.operate == 2 ||this.state.operate == 3||this.state.operate == 5||this.state.operate == 10||this.state.operate == 11) ? '': 't-DN'}>
                    <div style={{background:'#f2f3f5',height:'35px',padding:'10px 5px'}}><span className="t-FCddblue"><i className="iconfont icon-back t-rotate-180 t-FS14"></i>{this.state.operate==1?"审批意见":this.state.operate==2?'驳回意见':this.state.operate==3?'转交意见':this.state.operate==5?'跳转意见':this.state.operate==10?'完成意见':'签阅意见'}</span><span className="t-FCddblue t-FR" onClick={this.selectCommonwords.bind(this)}>常用语</span></div>
                    <TextareaField
                        readOnly={false}
                        minRows={10} maxRows={13}
                        placeholder={this.state.operate==1?"请输入审批意见":this.state.operate==2?'请输入驳回意见':this.state.operate==3?'请输入转交意见':this.state.operate==5?'请输入跳转意见':this.state.operate==10?'请输入完成意见':'请输入签阅意见'}
                        value={this.state.spyj}
                        onChange={this.changeSpyj.bind(this)}/>
					<CheckboxField
                            className={this.state.hasCommentField == '1'?"":"t-DN"}
                            data={this.state.savePhraseList}
                            mode="list"
                            onChange={this.selectSavePhrase.bind(this)}
                            required={false}
                            />
                    <Slot
                        ref="slotCommonwords"
                        data={this.state.phraseList}
                        value={this.state.choosePhrase}
                        title="选择常用语"
                        onConfirm={this.handleConfirmCommonwords.bind(this)}
                        onChange={this.handleChangeCommonwords.bind(this)}
                        /> 
                	</Group.List>
					<Group.List className={this.state.operate == 1?'':'t-DN'}>
							<div className={this.state.nextActivityList.length==0 && this.state.nextRadomList.length == 0?'t-DN':''} style={{background:'#f2f3f5',height:'35px',padding:'10px 5px'}}><span className="t-FCddblue"><i className="iconfont icon-back t-rotate-180 t-FS14"></i>审批环节</span></div>
							
							{/* 随机活动 */}
							<HBox vAlign="center" className={this.state.nextRadomList.length==0?'t-DN':'t-BB1 t-PT8 t-PB8'}>
								<Box className="t-LH24 t-FS14 t-PL18 t-FCa" flex={1}>随机活动</Box>
							</HBox>
							{
							this.state.nextRadomList.map(function(item,i){
							return (
								<div>
									<HBox vAlign="center" className="t-BB1">
									<HBox flex={1} className="t-PL16 t-PT10 t-PB10"  onClick={this.handleChecked.bind(this,i,item,"radom")}>
										<Box id={i} className={item.checked == false?"t-checkbox-field-icon-list un-checked":item.disable?"t-checkbox-field-icon checked disable t-checkbox-field-icon-list":"t-checkbox-field-icon-list"}   >
										<i className="iconfont icon-checked t-FCf t-FS14"></i>
										</Box>
										<Box className="t-LH24 t-FS16 t-PL18 t-omit" flex={1}>{item.name}</Box>
									</HBox>
									<Box className="t-PL16 t-PR16" onClick={this.handleShow.bind(this,i,item.arrow,item.show)}>
										<i className={item.arrow?"iconfont icon-arrow-up t-FCc":"iconfont icon-arrow-down t-FCc"}></i>
									</Box>
									</HBox>
									<Box className={item.show?"":"t-DN"} >
										<SelectMember 
											required={false}
											readOnly={item.selectUserReadOnly}
											label={'审批人'}
											placeholder="请选择"
											code={item.code}
											chooseType={item.chooseType}
											checkType={item.participantMode=='0'?'radio':'checkbox'}
											ref={item.value+"_"+i}
											isDelete={true}
											defaultValue={item.personValue}
											commonUsedData={item.commonUsedData}
											onChange={this.getRadomChoosePerson.bind(this,i)}
											includeDel={item.selectUserReadOnly ? "1" : "0"}
										/>
									</Box>
								</div>
							)}.bind(this))}

							{/* 后继活动 */}
							<HBox vAlign="center" className={this.state.nextActivityList.length==0?'t-DN':'t-BB1 t-PT8 t-PB8'}>
								<Box className="t-LH24 t-FS16 t-PL16 t-FCa" flex={1}>后继活动</Box>
							</HBox>
							{
							this.state.nextActivityList.map(function(item,i){
							return (
								<div>
									<HBox vAlign="center" className="t-BB1">
									<HBox flex={1} className="t-PL16 t-PT10 t-PB10"  onClick={this.handleChecked.bind(this,i,item,"next")}>
										<Box id={i} className={item.checked == false?"t-checkbox-field-icon-list un-checked":item.disable?"t-checkbox-field-icon checked disable t-checkbox-field-icon-list":"t-checkbox-field-icon-list"}   >
										<i className="iconfont icon-checked t-FCf t-FS14"></i>
										</Box>
										<Box className="t-LH24 t-FS16 t-PL18 t-omit" flex={1}>{item.name}</Box>
									</HBox>
									<Box className="t-PL16 t-PR16" onClick={this.handleShow.bind(this,i,item.arrow,item.show)}>
										<i className={item.arrow?"iconfont icon-arrow-up t-FCc":"iconfont icon-arrow-down t-FCc"}></i>
									</Box>
									</HBox>
									<Box className={item.show?"":"t-DN"} >
										<SelectMember 
											required={false}
											readOnly={item.selectUserReadOnly}
											label={'审批人'}
											placeholder="请选择"
											code={item.code}
											chooseType={item.chooseType}
											checkType={item.participantMode=='0'?'radio':'checkbox'}
											ref={item.value+"_"+i}
											isDelete={true}
											defaultValue={item.personValue}
											commonUsedData={item.commonUsedData}
											onChange={this.getChoosePerson.bind(this,i)}
											includeDel={item.selectUserReadOnly ? "1" : "0"}
										/>
									</Box>
								</div>
							)}.bind(this))}

							{/* 紧急状态 */}
                            <div className={this.state.urgentHidden==false?"":"t-DN"} style={{background:'#f2f3f5',height:'35px',padding:'10px 5px'}}><span className="t-FCddblue"><i className="iconfont icon-back t-rotate-180 t-FS14"></i>紧急状态</span></div>
                            <CheckboxField
                                className={this.state.urgentHidden==false?"":"t-DN"}
                                data={this.state.urgentList}
                                mode="list"
                                onChange={this.selectUrgent.bind(this)}
                                required={false}
                                />
                    </Group.List>
					<div className={this.state.directlySubmit=='0'?"t-P0 t-bottom-fixed":'t-DN'}>
					<Button.Group>
                        <Button type="primary" display="banner"
                                onClick={this.handleSubmitClick.bind(this)}>确认</Button>
                        <Button type="secondary" display="banner" onClick={this.handleCancelClick.bind(this)}>取消</Button>
                    </Button.Group>
					</div>
			</div>
		)
	}
}
